#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    // 设置行数、列数
    ui->table_widget->setRowCount(5);
    ui->table_widget->setColumnCount(3);

    // 设置水平表头
    ui->table_widget->setHorizontalHeaderLabels(QStringList() << "姓名" << "性别" << "年龄");

    // 设置正文
    QStringList age_list, sex_list, name_list;
    age_list << "19" << "20" << "30" << "20" << "30";
    sex_list << "男" << "男" << "男" << "男" << "男";
    name_list << "张飞" << "关羽" << "赵云" << "黄忠" << "马超";

    for (int i = 0; i < 5; i++) {
        ui->table_widget->setItem(i, 0, new QTableWidgetItem(name_list[i]));
        ui->table_widget->setItem(i, 1, new QTableWidgetItem(sex_list[i]));
        ui->table_widget->setItem(i, 2, new QTableWidgetItem(age_list[i]));
    }
}

Widget::~Widget()
{
    delete ui;
}

